package com.aidex.biz.controller;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.PublishUser;
import com.aidex.biz.service.PublishUserService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 发布信息用户操作Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2025-04-29
 */
@RestController
@RequestMapping("/biz/sysPublishUser")
public class PublishUserController extends BaseController
{
    @Autowired
    private PublishUserService publishUserService;

    /**
     * 查询发布信息用户操作列表
     */
    @PreAuthorize("@ss.hasPermi('biz:sysPublishUser:list')")
    @GetMapping("/list")
    public R<PageInfo> list(PublishUser publishUser, HttpServletRequest request, HttpServletResponse response)
    {
        if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                publishUser.setCompanyId(null);
        }else{
                     publishUser.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                 }
        publishUser.setPage(new PageDomain(request, response));
        return R.data(publishUserService.findPage(publishUser));
    }

    /**
     * 获取发布信息用户操作详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:sysPublishUser:query')")
    @GetMapping(value = "/{id}")
    public R<PublishUser> detail(@PathVariable("id") String id)
    {
        return R.data(publishUserService.get(id));
    }

    /**
     * 新增发布信息用户操作
     */
    @PreAuthorize("@ss.hasPermi('biz:sysPublishUser:add')")
    @Log(title = "发布信息用户操作", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  PublishUser publishUser)
    {
        return R.status(publishUserService.save(publishUser));
    }

    /**
     * 修改发布信息用户操作
     */
    @PreAuthorize("@ss.hasPermi('biz:sysPublishUser:edit')")
    @Log(title = "发布信息用户操作", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated PublishUser publishUser)
    {
        return R.status(publishUserService.save(publishUser));
    }


    /**
     * 删除发布信息用户操作
     */
    @PreAuthorize("@ss.hasPermi('biz:sysPublishUser:remove')")
    @Log(title = "发布信息用户操作", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(publishUserService.deletePublishUserByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:sysPublishUser:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(publishUserService.findMaxSort(new PublishUser()));
    }

    /**
     * 导出发布信息用户操作列表
     */
    @PreAuthorize("@ss.hasPermi('biz:sysPublishUser:export')")
    @Log(title = "发布信息用户操作", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(PublishUser publishUser)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    publishUser.setCompanyId(null);
            }else{
                         publishUser.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<PublishUser> list = publishUserService.findList(publishUser);
        ExcelUtil<PublishUser> util = new ExcelUtil<PublishUser>(PublishUser.class);
        return util.exportExcel(list, "发布信息用户操作数据");
    }

}
